package com.demo.consumer.controller.demoinfo;

import com.demo.consumer.controller.apm.ApmDeomController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class DemoConsumerInfo {

    private static final Logger log = LoggerFactory.getLogger(ApmDeomController.class);

    @GetMapping("info")
    public String MsgInfo(){
        log.info("/info echo this is DemoConsumer!");
        return "This is DemoConsumer!";
    }


    @Autowired
    private HttpServletRequest request;
    int count = 0;
    @GetMapping("instance/info")
    public String MsgInstanceInfo(){

        System.out.println(request.getServerName()+":"+request.getServerPort());
        count++;
        log.info("/instance/info 响应地址：{} {}", request.getServerName(), request.getServerPort());
        return "第" + count + "次响应服务地址:" + request.getServerName()+":"+request.getServerPort();
    }

    public String defaultFallback(){
        log.info("defaultFallback 默认Fallback方法");
        return "默认Fallback方法：暂时无法响应";
    }

}
